import ddddocr

from tool.get_log import GetLogging

logger = GetLogging().get_logging()


def get_verify(driver):
    try:
        screenshot = driver.page_get_verify_img()
        if screenshot is None:
            logger.error(f"未获取到有效的验证码图片数据")
            raise Exception("未获取到有效的验证码图片数据")
        ocr = ddddocr.DdddOcr(show_ad=False)
        verify = ocr.classification(screenshot)
        logger.info(f"验证码识别成功: {verify}")
        return verify
    except Exception as e:
        logger.error(f"验证码识别失败，错误信息: {e}")
        raise
